import { RegisterService, registerService } from './service/register';
import { PushService, pushService } from './service/push';
import { V, Connection } from 'e:/mjwork/x-engine';
import {X} from "e:/mjwork/xorm";
import { AccountController } from './hall/account';

import * as express from "express";
import * as http from "http";
import { md5 } from 'locutus/php/strings';
import { User } from './model/user';
import { RoomController } from './hall/room';
import { UUID, SetCache } from './utils';

//导入需要的控制器
AccountController;
RoomController;

//注册需要的模型
User;

//注册核心游戏控制器


//启动控制器
const app = express();
const server = http.createServer(app);
V.startExpressServer({
    app : app,
    server :server,
});
server.listen(8011);

//启动模型
X.startORM({
    type: 'mysql',
    name: "default",
    host: "127.0.0.1",
    port: 3306,
    username: "root",
    password: "123",
    database: "nwgame",
    tablesPrefix: "",
    debug : true
});


//启动游戏调度中心

//单个进程开启的房间数
// const rooms = 500;
// const serverList = ['red','orange','yellow'];
// const flag = "red";

//服务器超时延迟
//unit : s
const serverExprTime = 10;
//服务器心跳
//unit : ms
const serverHeart = 5000;

//服务器唯一标识
const serverUUID = (global as any).ServerUUID  = UUID();

//事件推送循环
const pushServiceTime = 1000;

//注册服务器
registerService.loop(serverUUID,serverHeart,serverExprTime);

//推送循环
pushService.loop(pushServiceTime);



